/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Form;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.Command;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BoxLayout;

/**
 *
 * @author Kvest
 */
public class FeedForm extends Form implements ActionListener
{
    public static final int OK_ID = 1;
    public static final int BACK_ID = 2;

    private Command ok;
    private Command back;
    private FormAction listener;

    private TextField time;

    public FeedForm(FormAction listener)
    {
        super("Время подачи");
        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        addCommandListener(this);

        back = new Command("Назад", BACK_ID);
        addCommand(back);

        ok = new Command("Ok", OK_ID);
        addCommand(ok);

        addComponent(new Label("Время подачи"));
        time = new TextField();
        time.setSelectCommandText("");
        time.setInputModeOrder(new String[]{"123"});
        time.setConstraint(TextArea.NUMERIC);
        addComponent(time);
    }

    public void show()
    {
        time.setText(ViewManager.getViewManager().getTenMinutesText());
        
        super.show();
    }

    public String getFeedTime()
    {
        return time.getText();
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.commandAction(evt.getCommand().getId());
        }
    }
}
